<#assign parentPKColumn = "">

package ${packagePath}.model.impl;


import java.sql.Types;
import java.io.Serializable;
import com.liferay.portal.kernel.util.GetterUtil;
public class ${entity.name}ModelImpl  {

	public static final String TABLE_NAME = "${entity.table}";

	public static final Object[][] TABLE_COLUMNS = {
		<#list entity.getRegularColList() as column>
			<#assign sqlType = serviceBuilder.getSqlType(packagePath + ".model." + entity.getName(), column.getName(), column.getType())>

			{"${column.DBName}", new Integer(Types.${sqlType})}

			<#if column_has_next>
				,
			</#if>
		</#list>
	};

	public static final String TABLE_SQL_CREATE = "${serviceBuilder.getCreateTableSQL(entity)}";

	public static final String TABLE_SQL_DROP = "drop table ${entity.table}";

	public static final String DATA_SOURCE = "${entity.dataSource}";

	public static final String SESSION_FACTORY = "${entity.sessionFactory}";

	public static final String TX_MANAGER = "${entity.getTXManager()}";

	<#list entity.columnList as column>
		<#if column.mappingTable??>
			public static final boolean FINDER_CACHE_ENABLED_${stringUtil.upperCase(column.mappingTable)} =

			<#assign entityShortName = stringUtil.shorten(entity.name, 10, "")>


			;
		</#if>
	</#list>


	public ${entity.name}ModelImpl() {
	}

	public ${entity.PKClassName} getPrimaryKey() {
		<#if entity.hasCompoundPK()>
			return new ${entity.PKClassName}(

			<#list entity.PKList as column>
				_${column.name}

				<#if column_has_next>
					,
				</#if>
			</#list>

			);
		<#else>
			return _${entity.PKList[0].name};
		</#if>
	}

	public void setPrimaryKey(${entity.PKClassName} pk) {
		<#if entity.hasCompoundPK()>
			<#list entity.PKList as column>
				set${column.methodName}(pk.${column.name});
			</#list>
		<#else>
			set${entity.PKList[0].methodName}(pk);
		</#if>
	}

	public Serializable getPrimaryKeyObj() {
		<#if entity.hasCompoundPK()>
			return new ${entity.PKClassName}(

			<#list entity.PKList as column>
				_${column.name}

				<#if column_has_next>
					,
				</#if>
			</#list>

			);
		<#else>
			return

			<#if entity.hasPrimitivePK()>
				new ${serviceBuilder.getPrimitiveObj("${entity.PKClassName}")} (
			</#if>

			_${entity.PKList[0].name}

			<#if entity.hasPrimitivePK()>
				)
			</#if>

			;
		</#if>
	}

	<#list entity.regularColList as column>
		<#if column.name == "classNameId">
			public String getClassName() {
				if (getClassNameId() <= 0) {
					return StringPool.BLANK;
				}

				return PortalUtil.getClassName(getClassNameId());
			}
		</#if>

		public ${column.type} get${column.methodName}() {
			<#if column.type == "String" && column.isConvertNull()>
				return GetterUtil.getString(_${column.name});
			<#else>
				return _${column.name};
			</#if>
		}

		<#if column.type== "boolean">
			public ${column.type} is${column.methodName}() {
				return _${column.name};
			}
		</#if>

		public void set${column.methodName}(${column.type} ${column.name}) {
			<#if column.name == "uuid">
				_uuid = uuid;

				<#if column.isFetchFinderPath()>
					if (_originalUuid == null) {
						_originalUuid = uuid;
					}
				</#if>
			<#else>
				_${column.name} = ${column.name};

				<#if column.isFetchFinderPath() || ((parentPKColumn != "") && (parentPKColumn.name == column.name))>
					<#if column.isPrimitiveType()>
						if (!_setOriginal${column.methodName}) {
							_setOriginal${column.methodName} = true;
					<#else>
						if (_original${column.methodName} == null) {
					</#if>

						_original${column.methodName} = ${column.name};
					}
				</#if>
			</#if>
		}

		<#if column.isFetchFinderPath() || ((parentPKColumn != "") && (parentPKColumn.name == column.name))>
			public ${column.type} getOriginal${column.methodName}() {
				<#if column.type == "String" && column.isConvertNull()>
					return GetterUtil.getString(_original${column.methodName});
				<#else>
					return _original${column.methodName};
				</#if>
			}
		</#if>
	</#list>


	<#if (entity.PKClassName == "long") && !stringUtil.startsWith(entity.name, "Expando")>
		public ExpandoBridge getExpandoBridge() {
			if (_expandoBridge == null) {
				_expandoBridge = new ExpandoBridgeImpl(${entity.name}.class.getName(), getPrimaryKey());
			}

			return _expandoBridge;
		}
	</#if>




	public int hashCode() {
		<#if entity.hasPrimitivePK()>
			<#if entity.PKClassName == "int">
				return getPrimaryKey();
			<#else>
				return (int)getPrimaryKey();
			</#if>
		<#else>
			return getPrimaryKey().hashCode();
		</#if>
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();

		<#list entity.regularColList as column>
			<#if column_index == 0>
				sb.append("{${column.name}=");
				sb.append(get${column.methodName}());
			<#elseif column_has_next>
				sb.append(", ${column.name}=");
				sb.append(get${column.methodName}());
			<#else>
				sb.append(", ${column.name}=");
				sb.append(get${column.methodName}());
				sb.append("}");
			</#if>
		</#list>

		return sb.toString();
	}

	public String toXmlString() {
		StringBuilder sb = new StringBuilder();

		sb.append("<model><model-name>");
		sb.append("${packagePath}.model.${entity.name}");
		sb.append("</model-name>");

		<#list entity.regularColList as column>
			sb.append("<column><column-name>${column.name}</column-name><column-value><![CDATA[");
			sb.append(get${column.methodName}());
			sb.append("]]></column-value></column>");
		</#list>

		sb.append("</model>");

		return sb.toString();
	}

	<#list entity.regularColList as column>
		private ${column.type} _${column.name};

		<#if column.isFetchFinderPath() || ((parentPKColumn != "") && (parentPKColumn.name == column.name))>
			private ${column.type} _original${column.methodName};

			<#if column.isPrimitiveType()>
				private boolean _setOriginal${column.methodName};
			</#if>
		</#if>
	</#list>

	<#if (entity.PKClassName == "long") && !stringUtil.startsWith(entity.name, "Expando")>
		private transient ExpandoBridge _expandoBridge;
	</#if>

}